package com.chaoyong.higo.adapter;

import com.chaoyong.higo.R;
import com.chaoyong.higo.base.BaseAdapter;
import com.chaoyong.higo.utils.ViewHolder;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 设置
 * @author zk
 *
 */
public class SettingsAdapter extends BaseAdapter<Object> {

	//private String[] itemsName = { "个人资料", "收货地址", "账户安全", "关于我们", "客服热线" };
	private String[] itemsName = { "个人资料", "收货地址", "账户安全", "客服热线" };
	private TextView setting_tel_num;
	private TextView setting_item_tv;
	private ImageView setting_right_lv;
	private View itemView;// 间隔作用的view

	public SettingsAdapter(Context context) {
		super(context);
	}

	@Override
	public int getCount() {
		return itemsName.length;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_settings, null);
		}

		setting_tel_num = ViewHolder.get(convertView, R.id.setting_tel_num);
		setting_right_lv = ViewHolder.get(convertView, R.id.setting_right_lv);
		setting_item_tv = ViewHolder.get(convertView, R.id.setting_item_tv);
		itemView = ViewHolder.get(convertView, R.id.item_view);

		setting_item_tv.setText(itemsName[position]);

		if (position == 3) {
			itemView.setVisibility(View.VISIBLE);
		} else {
			itemView.setVisibility(View.GONE);
		}

		if (position == 3) {
			setting_tel_num.setVisibility(View.VISIBLE);
			setting_right_lv.setVisibility(View.GONE);

			final String tel = setting_tel_num.getText().toString().trim();
			setting_tel_num.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent(Intent.ACTION_DIAL);
					Uri data = Uri.parse("tel:" + tel);
					intent.setData(data);
					mContext.startActivity(intent);
				}
			});
		} else {
			setting_tel_num.setVisibility(View.GONE);
			setting_right_lv.setVisibility(View.VISIBLE);
		}

		return convertView;
	}

}
